﻿<div class="page-container" id="admui-pageContent">
    <div class="page animation-fade page-forms">
        <div class="page-content">
            <div class="panel">
                <div class="page-header">
                    <h1 class="page-title">团队列表</h1>
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item">
                            <a class="icon wb-home" href="javascript:;">团队管理</a>
                        </li>
                        <li class="breadcrumb-item active">战队列表</li>
                    </ol>
                </div>
                <div class="panel-body">
                    <div class="panel-body container-fluid">
                        <h4 class="example-title">团队信息</h4>
                        <div class="row">
                            <div class="form-group col-sm-4">
                                <label class="control-label" for="inputBasicPassword">团队名称</label>
                                <input type="text" class="form-control" id="tuanduimingcheng" name="" placeholder="请输入战队名称" autocomplete="off" />
                            </div>
                            <div class="form-group col-sm-4">
                                <label class="control-label" for="inputBasicPassword">团队经理</label>
                                <select class="form-control" id="tuanduijingli" name="" data-fv-notempty="true" data-fv-field="requiredSelect"></select>
                            </div>
                            <div class="form-group col-sm-4" style="padding-top:27px">
                                <button type="button" id="bt_ChaXun" class="btn btn-block btn-success" style="width: 45%; float: left;" onclick="bang('查')"><i class="icon wb-search"></i>查询</button>
                                <span style="padding-left:10%"></span>
                                <button typeutton" id="bt_ChongZhi" class="btn btn-outline btn-success" style="width: 45%;" onclick="chongzhi();">重置</button>
                            </div>
                        </div>
                    </div>
                    <table class="table table-bordered table-hover dataTable table-striped w-full text-nowrap" id="dataTableExample" data-plugin="dataTable">
                        <thead>
                            <tr>
                                <th>团队名称</th>
                                <th>团队经理</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tfoot>
                            <tr>
                                <th>团队名称</th>
                                <th>团队经理</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                        </tfoot>
                        <tbody></tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">

                $(document).ready(function () {
                    $("#TuanDuiGuanLi").click();
                    TuanduiJingLIBangDing();
                    bang('不查');
                });
                //绑定
    function TuanduiJingLIBangDing() {
        $.ajax({
            type: 'post',
            url: '../TuanDui/TuanDuiJingLiShuJu',
            async: false,
            dataType: 'json',
            success: function (date) {
                var ddl = $("#tuanduijingli");
                ddl.append("<option value='0'>请选择</option>");
                $(date).each(function (key) {
                    var opt = $("<option></option>").text(date[key].xingMing).val(date[key].id);
                    ddl.append(opt);
                })
            },
        })
    }
                //重置
                function chongzhi()
                {
                    $("#tuanduimingcheng").val("");
                    $('#tuanduijingli option').remove();
                    TuanduiJingLIBangDing();
                    bang('不查')
                }
    function bang(panduan) {
        var tuanduimingcheng = "";
        var tuanduijingli = 0;
                    if (panduan == "查") {
                        tuanduimingcheng = $("#tuanduimingcheng").val();
                        tuanduijingli = $("#tuanduijingli").find("option:selected").val();
                    } else if (panduan == "不查") {
                        tuanduimingcheng = "";
                        tuanduijingli = 0;
                    }
                    var lang = {
                        "sProcessing": "大量处理中，请稍后...",
                        "sLengthMenu": "每页 _MENU_ 项",
                        "sZeroRecords": "没有匹配结果",
                        "sInfo": "当前显示第 _START_ 至 _END_ 项，共 _TOTAL_ 项。",
                        "sInfoEmpty": "当前显示第 0 至 0 项，共 0 项",
                        "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                        "sInfoPostFix": "",
                        "sSearch": "搜索:",
                        "sUrl": "",
                        "sEmptyTable": "表中数据为空",
                        "sLoadingRecords": "载入中...",
                        "sInfoThousands": ",",
                        "oPaginate": {
                            "sFirst": "首页",
                            "sPrevious": "上页",
                            "sNext": "下页",
                            "sLast": "末页",
                            "sJump": "跳转"
                        },
                        "oAria": {
                            "sSortAscending": ": 以升序排列此列",
                            "sSortDescending": ": 以降序排列此列"
                        }
                    };
                    $("#dataTableExample").dataTable().fnDestroy();
                    $('#dataTableExample').dataTable({
                        "order": [[0, "asc"]],
                        "language": lang,
                        "processing": true,
                        "serverSide": true,
                        //"bStateSave": true,//状态保持模式
                        "searching": false,//禁用搜索
                        ajax: function (data, callback, settings) {
                            //封装请求参数
                            //console.log(data);
                            var param = {};
                            param.limit = data.length;//页面显示记录条数，在页面显示每页显示多少项的时候
                            param.start = data.start;//开始的记录序号
                            param.page = (data.start / data.length) + 1;//当前页码
                            param.dir = data.order[0].dir;
                            param.column = data.order[0].column;

                            param.tuanduimingcheng = tuanduimingcheng;
                            param.tuanduijingli = tuanduijingli;

                            //console.log(param);

                            //ajax请求数据
                            $.ajax({
                                type: "POST",
                                url: "../TuanDui/InitializationDataTable",
                                cache: false,  //禁用缓存
                                data: param,  //传入组装的参数
                                dataType: "json",
                                success: function (result) {
                                    console.log(result);
                                    //setTimeout仅为测试延迟效果
                                    setTimeout(function () {
                                        //封装返回数据
                                        var returnData = {};
                                        returnData.draw = data.draw;//这里直接自行返回了draw计数器,应该由后台返回
                                        returnData.recordsTotal = result.total;//返回数据全部记录
                                        returnData.recordsFiltered = result.total;//后台不实现过滤功能，每次查询均视作全部结果
                                        returnData.data = result.data;//返回的数据列表
                                        //console.log(returnData);
                                        //调用DataTables提供的callback方法，代表数据已封装完成并传回DataTables进行渲染
                                        //此时的数据需确保正确无误，异常判断应在执行此回调前自行处理完毕"orderable" : false
                                        callback(returnData);
                                    }, 200);
                                }
                            });
                        },
                        "columns": [
                            { "data": "TuanDuiMingCheng" },
                            { "data": "t_RenYuanBiao_JingLi.XingMing" },
                            { "data": "ZhuangTai" },
                            { "data": null }
                        ],
                        columnDefs: [{
                            //   指定第最后一列
                            targets: -1,
                            //加下面属性 不参与排序
                            sortable: false,
                            render: function (data, type, row, meta) {
                                if (row.ZhuangTai == "启用") {
                                    return '<button type="button" class="btn btn-outline btn-default" onclick="shebeiXG(' + row.Id + ')"><i class="icon wb-pencil" aria-hidden="true"></i>修改</button>   <button type="button" class="btn btn-outline btn-default" onclick="JinYong(' + row.Id + ')">禁用</button>';
                                } else {
                                    return '<button type="button" class="btn btn-outline btn-default" onclick="shebeiXG(' + row.Id + ')"><i class="icon wb-pencil" aria-hidden="true"></i>修改</button>   <button type="button" class="btn btn-outline btn-default" onclick="QiYong(' + row.Id + ')">启用</button>';
                                }
                            }
                        }]
                    });
                }

                function shebeiXG(id) {
                    location.href = "../TuanDui/TuanDuiPeiZhi?id=" + id;
                }

                function QiYong(id) {
                    $.ajax({
                        type: 'post',
                        url: '../TuanDui/QiYong',
                        async: false,
                        dataType: 'text',
                        data: { id: id },
                        success: function (date) {
                            if (date == "success") {
                                alert("更改成功!");
                                bang();
                            } else {
                                alert("失败");
                            }

                        },
                    })
                }

                function JinYong(id) {
                    $.ajax({
                        type: 'post',
                        url: '../TuanDui/JinYong',
                        async: false,
                        dataType: 'text',
                        data: { id: id },
                        success: function (date) {
                            if (date == "success") {
                                alert("更改成功!");
                                bang();
                            } else {
                                alert("失败");
                            }

                        },
                    })
                }

</script>
